package com.itheima.controller;

import com.itheima.domain.Users;
import com.itheima.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userservice;

    @RequestMapping("/doRegister")
    public String register(Users users){
         userservice.register(users);
        return "redirect:/pages/login.jsp";
    }

    @RequestMapping("/doLogin")
    public ModelAndView login(String username,String password){
       Users users =  userservice.login(username,password);
       ModelAndView mv = new ModelAndView();
       mv.addObject("user",users);
       mv.setViewName("success");
        return mv;
    }


}
